Matplotlib Tutorial Part 01: Introduction and Line

Source


In [3]:
%matplotlib inline
import matplotlib.pyplot as plt

Plotting Lines based on points


In [13]:
X = [1,2,3]
Y = [5,6,1]

plt.plot(X, Y)
plt.show()


Plotting Points


In [14]:
X = [1,2,3,4,9,3,7,1,2,8,5]
Y = [5,6,1,1,4,7,5,4,6,8,2]

plt.plot(X, Y,'*')
plt.show()


Plotting Math Functions


In [22]:
def f(x):
    return x**2

X = [i for i in range(-10,11)]
Y = [f(x) for x in X]

plt.plot(X,Y)
plt.show()


Plotting Random points


In [8]:
from random import randint

amount_points = 30

X = [i for i in range(amount_points)]
Y = [randint(0,9) for i in range(amount_points)]

plt.plot(X,Y,'.')
plt.show()